﻿using Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Linguist.LexTree
{
    /// <summary>
    /// A node representing a word in the HMM tree
    /// </summary>
    public class WordNode: Node
    {
        /// <summary>
        /// the pronunciation to wrap in this node
        /// </summary>
        private IPronunciation pronunciation;
        private Boolean _isFinal;
        /// <summary>
        /// true if the node is the final one
        /// </summary>
        public Boolean IsFinal
        {
            get { return _isFinal; }
        }

        /// <summary>
        /// Creates a word node
        /// </summary>
        /// <param name="pronunciation">the pronunciation to wrap in this node</param>
        /// <param name="probability">the word unigram probability</param>
        public WordNode(IPronunciation pronunciation, float probability) 
            :base(probability)
        {
            this.pronunciation = pronunciation;
            this._isFinal = pronunciation.getWord().isSentenceEndWord();
        }

        /// <summary>
        /// Gets the word associated with this node
        /// </summary>
        /// <returns>the word</returns>
        public IWord getWord() 
        {
            return pronunciation.getWord();
        }

        /// <summary>
        /// Gets the pronunciation associated with this node
        /// </summary>
        /// <returns>the pronunciation</returns>
        public IPronunciation getPronunciation() 
        {
            return pronunciation;
        }

        /// <summary>
        /// Gets the last unit for this word
        /// </summary>
        /// <returns></returns>
        public IUnit getLastUnit() 
        {
            return pronunciation.getUnits().Last();
        }

        /// <summary>
        /// Returns the successors for this node 
        /// throw NotSupportedException
        /// </summary>
        /// <returns>set of successor nodes</returns>
        public Node[] getSuccessors() 
        {
            throw new NotSupportedException("Not supported");
        }

        /// <summary>
        /// Returns a string representation for this object 
        /// </summary>
        /// <returns>a string representation</returns>
        override public String ToString() 
        {
            return "WordNode " + pronunciation.ToString() + " p " + this.LogUnigramProbability.ToString();
        }


    }
}
